'''
预约设置服务类,将一个服务封装成一个类
服务名OrderSettingService 类名 member_service
方法1:add                             方法名:add
方法2:getOrderSettingByMonth          方法名:get_order_setting_by_month
方法3:editNumberByDate                方法名:edit_number_by_date
'''
import json

from api.base_service import BaseService


class OrderSettingService(BaseService):

    def __init__(self):
        super().__init__()
        self.service_name = "OrderSettingService"
    # 添加预约设置 Definition： void add(List<OrderSetting> list)
    def add(self,data_list):
        resp = self.client.invoke(self.service_name, "add",data_list)
        # 成功:[{"orderDate":"2022-09-20 15:48:30","number":3852}] "null"
        # 失败:[{"orderDate":"2022-09-20","number":20}]  "Failed"
        # 失败:{"orderDate":"2022-09-20","number":"20"}   "No"
        if resp == "null":
            return True
        else:
            return False
    # 按月统计预约设置信息 Definition： Definition： List getOrderSettingByMonth(String date)
    def get_order_setting_by_month(self,data):
        resp = self.client.invoke(self.service_name, "getOrderSettingByMonth", data)
        # 成功:返回列表"[]"
        # 失败:2022 返回"Faild"
        if resp == "Failed":
            return None
        else:
            return json.loads(resp)

    #根据日期修改预约设置数量 void editNumberByDate(OrderSetting orderSetting)
    def edit_number_by_date(self,order_setting_data):
        # member是一个自定义类型.需要我们使用字典来传递,并增加class字段信息
        # 为了方便传参.将class字段封装到方法里即可
        order_setting_data["class"] = "com.itheima.pojo.OrderSetting"
        resp = self.client.invoke(self.service_name, "editNumberByDate", order_setting_data)
        # 成功:[{"orderDate":"2022-09-20 15:48:30","number":3852}] "null"
        # 失败:[{"orderDate":"2022-09-20","number":20}]  "Failed"
        # 失败:{"orderDate":"2022-09-20","number":"20"}   "No"
        if resp == "null":
            return True
        else:
            return False
if __name__ == '__main__':
    # 添加预约设置
    data_list =[{"orderDate":"2022-09-20 15:48:30","number":3852}]
    ms = OrderSettingService().add(data_list)
    print(type(ms),ms)

    # 按月统计预约设置信息
    # data = "2022-12"
    # ms = OrderSettingService().get_order_setting_by_month(data)
    # print(type(ms),ms)

    # 根据日期修改预约设置数量
    # order_setting_data = {"orderDate":"2021-06-13 16:50:00","number":120}
    # ms = OrderSettingService().edit_number_by_date(order_setting_data)
    # print(type(ms),ms)